/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CertificateCell.java
 *
 * Created on 29-03-2012, 23:10:04
 */
package Management;

import ConnectData.Config;
import ConnectData.getConnections;
import Register.MyMD5;
import UploadData.Database;
import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
import java.awt.HeadlessException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author s0lo
 */
public class CertificateCell extends javax.swing.JFrame {

    private Vector vtCertificateCell;
    private Vector vtCourse;
    private Vector vtMark;
    private static String user;
    private static String pw;
    private String oldPassword;
    private String newPassword;
    private String reNewPassword;
    private static String Access;

    /** Creates new form CertificateCell */
    public CertificateCell(String User, String pass, String Access) {
        try {
            UIManager.setLookAndFeel(new WindowsLookAndFeel());
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(AdminForm.class.getName()).log(Level.SEVERE, null, ex);
        }
        initComponents();
        loadCourseSearch();
        loadCertificateCell();
        this.user = User;
        this.pw = pass;
        this.Access = Access;
    }

    public void loadCourseSearch() {

        vtCourse = new Database().loadCourse(" order by CourseName");
        if (vtCourse.size() != 0) {
            for (int i = 0; i < vtCourse.size(); i++) {
                String cb = ((Vector) vtCourse.get(i)).get(1).toString();
                cblCourseSearch.add(cb, false);
            }
        }

    }

    public void loadCertificateCell() {
        String strSearch = " where '1'='1'";
        Vector listCourse = cblCourseSearch.SelectedItems();
        int courID = 0;
        int StuID;
        if (listCourse.size() > 0) {
            strSearch += " and CourseID in (";
            String temp = "";
            for (int i = 0; i < listCourse.size(); i++) {
                String courName = listCourse.get(i).toString();
                Vector vtCour = new Database().loadCourse(" where CourseName='" + courName + "'");
                if (vtCour.size() > 0) {
                    String CourName;
                    for (int j = 0; j < vtCour.size(); j++) {
                        CourName = ((Vector) vtCour.get(j)).get(1).toString();
                        if (CourName.equals(courName)) {
                            courID = Integer.parseInt(((Vector) vtCour.get(j)).get(0).toString());
                            temp += courID + ",";
                        }
                    }
                }
            }
            if (temp.equalsIgnoreCase("")) {
                temp = "0)";
            } else {
                temp = temp.substring(0, temp.length() - 1) + ")";
            }
            strSearch += temp;
        }



        String str = txtStuNameSearch.getText();
        if (!str.equals("")) {
            strSearch += " and StuName like '%" + str + "%' ";
        }

        strSearch += " and StatusCourse=0 order by StuName";
        vtCertificateCell = new Database().loadvwCetificateCell(strSearch);
        if (vtCertificateCell.size() != 0) {
            Vector vtCol = new Vector();
            Vector vtDisplay = new Vector();
            for (int i = 0; i < vtCertificateCell.size(); i++) {
                vtCol.add(((Vector) vtCertificateCell.get(i)).get(3).toString());
                vtCol.add(((Vector) vtCertificateCell.get(i)).get(4).toString());
                vtCol.add(((Vector) vtCertificateCell.get(i)).get(5).toString());
                vtCol.add(((Vector) vtCertificateCell.get(i)).get(6).toString());
                vtDisplay.add(vtCol);
                vtCol = new Vector();
            }

            for (int i = 0; i < ((Vector) vtDisplay.get(0)).size(); i++) {
                vtCol.add("Col " + (i + 1));
            }
            vtCol = new Vector();
            vtCol.add("Student Name");
            vtCol.add("Course Name");
            vtCol.add("Start Date");
            vtCol.add("End Date");
            DefaultTableModel dtm = new DefaultTableModel(vtDisplay, vtCol);
            tbInfo.setModel(dtm);
        } else {
            JOptionPane.showMessageDialog(this, "Not found appropriate data!");
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel4 = new javax.swing.JPanel();
        jPanel9 = new javax.swing.JPanel();
        lbUserName1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbInfo = new javax.swing.JTable();
        jPanel10 = new javax.swing.JPanel();
        jPanel13 = new javax.swing.JPanel();
        txtStuNameSearch = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        cblCourseSearch = new creator.components.CheckBoxList();
        jLabel14 = new javax.swing.JLabel();
        btnSearch = new javax.swing.JButton();
        btnDetail = new javax.swing.JToggleButton();
        btnClose1 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jPanel14 = new javax.swing.JPanel();
        txtOldPass = new javax.swing.JPasswordField();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        txtNewPass = new javax.swing.JPasswordField();
        txtRePass = new javax.swing.JPasswordField();
        jLabel19 = new javax.swing.JLabel();
        btnChange1 = new javax.swing.JToggleButton();
        btnClose2 = new javax.swing.JButton();
        lbUserName = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(153, 255, 204));
        jPanel1.setAutoscrolls(true);

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/90.6peopleonworld.jpg"))); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 1087, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 190, Short.MAX_VALUE)
        );

        jTabbedPane1.setBackground(new java.awt.Color(0, 255, 204));
        jTabbedPane1.setAutoscrolls(true);
        jTabbedPane1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jTabbedPane1.addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
                jTabbedPane1AncestorAdded(evt);
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
            }
        });

        jPanel4.setBackground(new java.awt.Color(204, 255, 204));
        jPanel4.setForeground(new java.awt.Color(0, 0, 51));

        jPanel9.setBackground(new java.awt.Color(204, 255, 204));
        jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jPanel9.setForeground(new java.awt.Color(0, 0, 51));
        jPanel9.setAutoscrolls(true);

        lbUserName1.setFont(new java.awt.Font("Tahoma", 1, 12));
        lbUserName1.setForeground(new java.awt.Color(0, 0, 51));
        lbUserName1.setText("   ");

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lbUserName1)
                .addGap(803, 803, 803))
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lbUserName1)
                .addContainerGap(393, Short.MAX_VALUE))
        );

        jScrollPane1.setBackground(new java.awt.Color(204, 255, 204));
        jScrollPane1.setAutoscrolls(true);
        jScrollPane1.setDoubleBuffered(true);
        jScrollPane1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jScrollPane1MouseClicked(evt);
            }
        });

        tbInfo.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        tbInfo.setToolTipText("To see details please click on appropriate row!");
        tbInfo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbInfoMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tbInfo);

        jPanel10.setBackground(new java.awt.Color(204, 255, 153));
        jPanel10.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Search", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14), new java.awt.Color(255, 102, 0))); // NOI18N
        jPanel10.setForeground(new java.awt.Color(0, 0, 51));
        jPanel10.setAutoscrolls(true);

        jPanel13.setBackground(new java.awt.Color(204, 255, 204));
        jPanel13.setBorder(javax.swing.BorderFactory.createTitledBorder(null, " Infomation", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12), new java.awt.Color(255, 0, 0))); // NOI18N
        jPanel13.setForeground(new java.awt.Color(0, 0, 51));

        txtStuNameSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtStuNameSearchActionPerformed(evt);
            }
        });

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel13.setForeground(new java.awt.Color(0, 0, 51));
        jLabel13.setText("Student Name :");

        cblCourseSearch.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cblCourseSearchMouseClicked(evt);
            }
        });

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel14.setForeground(new java.awt.Color(0, 0, 51));
        jLabel14.setText("Course :");

        javax.swing.GroupLayout jPanel13Layout = new javax.swing.GroupLayout(jPanel13);
        jPanel13.setLayout(jPanel13Layout);
        jPanel13Layout.setHorizontalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel13Layout.createSequentialGroup()
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel13)
                    .addComponent(jLabel14))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cblCourseSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtStuNameSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel13Layout.setVerticalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel13Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel13)
                    .addComponent(txtStuNameSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel14)
                    .addComponent(cblCourseSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel10Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addComponent(jPanel13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btnSearch.setFont(new java.awt.Font("Tahoma", 1, 12));
        btnSearch.setForeground(new java.awt.Color(0, 0, 51));
        btnSearch.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/tk.png"))); // NOI18N
        btnSearch.setText("Search");
        btnSearch.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        btnSearch.setMaximumSize(new java.awt.Dimension(111, 35));
        btnSearch.setMinimumSize(new java.awt.Dimension(111, 35));
        btnSearch.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseExited(java.awt.event.MouseEvent evt) {
                btnSearchMouseExited(evt);
            }
        });
        btnSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchActionPerformed(evt);
            }
        });

        btnDetail.setFont(new java.awt.Font("Tahoma", 1, 12));
        btnDetail.setForeground(new java.awt.Color(0, 0, 51));
        btnDetail.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/info.png"))); // NOI18N
        btnDetail.setText("Detail");
        btnDetail.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDetailActionPerformed(evt);
            }
        });

        btnClose1.setFont(new java.awt.Font("Tahoma", 1, 12));
        btnClose1.setForeground(new java.awt.Color(0, 0, 51));
        btnClose1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/close1.png"))); // NOI18N
        btnClose1.setText("Close");
        btnClose1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        btnClose1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnClose1ActionPerformed(evt);
            }
        });

        jButton1.setFont(new java.awt.Font("Tahoma", 1, 12));
        jButton1.setForeground(new java.awt.Color(0, 0, 51));
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/object_05.png"))); // NOI18N
        jButton1.setText("Confirm");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 583, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(btnSearch, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnDetail, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE)
                            .addComponent(btnClose1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(17, Short.MAX_VALUE))
            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup()
                    .addGap(2, 2, 2)
                    .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, 598, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(331, Short.MAX_VALUE)))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnSearch, javax.swing.GroupLayout.DEFAULT_SIZE, 38, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addComponent(btnDetail)
                .addGap(18, 18, 18)
                .addComponent(btnClose1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(49, 49, 49))
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup()
                    .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        jTabbedPane1.addTab("Certificate Cell", new javax.swing.ImageIcon(getClass().getResource("/icon/Course.jpg")), jPanel4); // NOI18N

        jPanel14.setBackground(new java.awt.Color(204, 255, 204));
        jPanel14.setForeground(new java.awt.Color(0, 0, 51));

        txtOldPass.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtOldPassActionPerformed(evt);
            }
        });

        jLabel17.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel17.setForeground(new java.awt.Color(0, 0, 51));
        jLabel17.setText("Old PassWord :");

        jLabel18.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel18.setForeground(new java.awt.Color(0, 0, 51));
        jLabel18.setText("New PassWord :");

        txtNewPass.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNewPassActionPerformed(evt);
            }
        });

        txtRePass.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtRePassActionPerformed(evt);
            }
        });

        jLabel19.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel19.setForeground(new java.awt.Color(0, 0, 51));
        jLabel19.setText("Re-PassWord :");

        btnChange1.setFont(new java.awt.Font("Arial", 1, 12));
        btnChange1.setForeground(new java.awt.Color(0, 0, 51));
        btnChange1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/save.png"))); // NOI18N
        btnChange1.setText("Save");
        btnChange1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnChange1ActionPerformed(evt);
            }
        });

        btnClose2.setFont(new java.awt.Font("Arial", 1, 12));
        btnClose2.setForeground(new java.awt.Color(0, 0, 51));
        btnClose2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/close1.png"))); // NOI18N
        btnClose2.setText("Close");
        btnClose2.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        btnClose2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnClose2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel14Layout = new javax.swing.GroupLayout(jPanel14);
        jPanel14.setLayout(jPanel14Layout);
        jPanel14Layout.setHorizontalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel14Layout.createSequentialGroup()
                .addGap(288, 288, 288)
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel14Layout.createSequentialGroup()
                        .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel17)
                            .addComponent(jLabel19))
                        .addGap(23, 23, 23))
                    .addGroup(jPanel14Layout.createSequentialGroup()
                        .addComponent(jLabel18)
                        .addGap(18, 18, 18)))
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtOldPass, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtNewPass, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtRePass, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel14Layout.createSequentialGroup()
                        .addComponent(btnChange1, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnClose2, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(325, Short.MAX_VALUE))
        );
        jPanel14Layout.setVerticalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel14Layout.createSequentialGroup()
                .addGap(64, 64, 64)
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(txtOldPass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(txtNewPass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel18))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel19)
                    .addComponent(txtRePass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnChange1, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnClose2, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(241, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Change Password", new javax.swing.ImageIcon(getClass().getResource("/icon/pass.png")), jPanel14); // NOI18N

        lbUserName.setFont(new java.awt.Font("Tahoma", 1, 12));
        lbUserName.setForeground(new java.awt.Color(0, 0, 51));
        lbUserName.setText("   ");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(444, 444, 444)
                .addComponent(lbUserName)
                .addContainerGap(641, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 936, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(161, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(4, 4, 4)
                .addComponent(lbUserName)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 485, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(38, 38, 38))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 939, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 699, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnDetailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDetailActionPerformed
        // TODO add your handling code here:
        int rscurrent = tbInfo.getSelectedRow();
        if (rscurrent >= 0) {
            int CRID = Integer.parseInt(((Vector) vtCertificateCell.get(rscurrent)).get(0).toString());
            int StuID = Integer.parseInt(((Vector) vtCertificateCell.get(rscurrent)).get(1).toString());
            int CourID = Integer.parseInt(((Vector) vtCertificateCell.get(rscurrent)).get(2).toString());

            new CourseDetail(CRID, StuID, CourID,"0");

        } else {
            JOptionPane.showMessageDialog(this, "Please Select Course do you want Watch Detail!");
        }
    }//GEN-LAST:event_btnDetailActionPerformed

    private void btnSearchMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnSearchMouseExited
        // TODO add your handling code here:
}//GEN-LAST:event_btnSearchMouseExited

    private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed
        // TODO add your handling code here:
        //Difine search string
        loadCertificateCell();
}//GEN-LAST:event_btnSearchActionPerformed

    private void btnClose1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnClose1ActionPerformed
        // TODO add your handling code here:
        int i = JOptionPane.showConfirmDialog(this, "Are you sure you want to exit! ", "Exit", 2);
        if (i == 0) {
            this.dispose();
        }
}//GEN-LAST:event_btnClose1ActionPerformed

    private void tbInfoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbInfoMouseClicked
        // TODO add your handling code here:
        int rscurrent = tbInfo.getSelectedRow();
        String strInfo = "";
        String gender = null;
        Vector vtDetail = (Vector) vtCertificateCell.get(rscurrent);

        int CRID = Integer.parseInt(vtDetail.get(0).toString());
        int StuID = Integer.parseInt(vtDetail.get(1).toString());
        int CourID = Integer.parseInt(vtDetail.get(2).toString());
        Vector count = new Database().loadvwCourseDetail(" where CourseID=" + CourID + " and StuID=" + StuID + " and StatusSubject=1 order by SubID");
        Vector sub = new Database().loadSubjectDetail(" where CourseID=" + CourID);
        strInfo += "Student Name :\t\t " + vtDetail.get(3).toString().trim() + "\n";
        strInfo += "Course Name :\t\t " + vtDetail.get(4).toString().trim() + "\n";
        strInfo += "Start Date  :\t\t  " + vtDetail.get(5).toString().trim().substring(0, 10) + "\n";
        strInfo += "End Date  :\t\t  " + vtDetail.get(6).toString().trim().substring(0, 10) + "\n";
        strInfo += " number Subject Pass :\t\t " + count.size() + "/" + sub.size() + "\n";
        Vector vtPay = new Database().loadAVGMarkCertificate("select Status from Payment where CRID=" + CRID + " and Status=1");
        if (vtPay.size() != 0) {
            strInfo += "Status Payment : \t\t Complete " + "\n";
        } else {
            strInfo += "Status Payment : \t\t Not Complete " + "\n";
        }

        JOptionPane.showMessageDialog(this, strInfo, "Detail Informations", JOptionPane.DEFAULT_OPTION);
}//GEN-LAST:event_tbInfoMouseClicked

    private void jScrollPane1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jScrollPane1MouseClicked
        // TODO add your handling code here:
}//GEN-LAST:event_jScrollPane1MouseClicked

    private void cblCourseSearchMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cblCourseSearchMouseClicked
        // TODO add your handling code here:
}//GEN-LAST:event_cblCourseSearchMouseClicked

    private void btnChange1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChange1ActionPerformed
        // TODO add your handling code here:

        if (validateInformation()) {
            Connection cn = null;
            PreparedStatement pst = null;
            ResultSet rs = null;
            try {
                cn = new Config().cn;
                pst = cn.prepareStatement("select * from Users where UserName=? order by UserLevel");
                pst.setString(1, user);
                rs = pst.executeQuery();
                while (rs.next()) {
                    String pwmd = MyMD5.getMD5String(txtOldPass.getText());
                    if (!rs.getString("UserPassword").equals(pwmd)) {
                        JOptionPane.showMessageDialog(this, "Your old password do not correct");
                        txtOldPass.setText("");
                        txtOldPass.requestFocus();
                    } else {
                        cn = new Config().cn;
                        String strUpdate = "update Users set UserPassword=? where UserName=?";
                        pst = cn.prepareStatement(strUpdate);
                        pst.setString(1, MyMD5.getMD5String(txtNewPass.getText().trim()));
                        pst.setString(2, user);
                        pst.executeUpdate();
                        JOptionPane.showMessageDialog(this, "Change Password Successfully");
                        txtOldPass.setText("");
                        txtNewPass.setText("");
                        txtRePass.setText("");
                    }
                }
            } catch (SQLException se) {
            } catch (HeadlessException he) {
            } catch (Exception e) {
            } finally {
                getConnections.closeObject(rs);
                getConnections.closeObject(pst);
                getConnections.closeObject(cn);
            }
        }
    }//GEN-LAST:event_btnChange1ActionPerformed

    private void btnClose2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnClose2ActionPerformed
        // TODO add your handling code here:
        int i = JOptionPane.showConfirmDialog(this, "Are you sure you want to exit! ", "Exit", 2);
        if (i == 0) {
            this.dispose();
        }
}//GEN-LAST:event_btnClose2ActionPerformed

    private void jTabbedPane1AncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_jTabbedPane1AncestorAdded
        // TODO add your handling code here:
}//GEN-LAST:event_jTabbedPane1AncestorAdded

    private void txtStuNameSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtStuNameSearchActionPerformed
        // TODO add your handling code here:
        btnSearchActionPerformed(evt);
}//GEN-LAST:event_txtStuNameSearchActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        int rscurrent = tbInfo.getSelectedRow();
        if (rscurrent >= 0) {
            Vector vtDetail = (Vector) vtCertificateCell.get(rscurrent);
            //  new StudentDetail(this, Integer.parseInt(vtDetail.get(0).toString()), rscurrent, Access);
            int CRID = Integer.parseInt(vtDetail.get(0).toString());
            int StuID = Integer.parseInt(vtDetail.get(1).toString());
            int CourID = Integer.parseInt(vtDetail.get(2).toString());
            Vector count = new Database().loadvwCourseDetail(" where CourseID=" + CourID + " and StuID=" + StuID + " and StatusSubject=1 order by SubID");
            vtMark = new Database().loadAVGMarkCertificate("select avg(Mark) as AVGMARK from vwCourseDetail  where CourseID=" + CourID
                    + " and StuID=" + StuID + " and StatusSubject=1 and (select Status from Payment where CRID=" + CRID + " and Status=1)=1 "
                    + " and (select Count(*) from SubjectDetail where CourseID=" + CourID + ")=" + count.size());
            String avgmark = "";
            if (vtMark.size() != 0) {
                for (int i = 0; i < vtMark.size(); i++) {
                    avgmark = ((Vector) vtMark.get(i)).get(0).toString();
                }
            }
            if (!avgmark.equalsIgnoreCase("null")) {
                new Database().UpdateCourseRegister(CRID, 1);
                int n = new Database().addCertificate(CRID, Float.parseFloat(avgmark));
                if (n > 0) {
                    JOptionPane.showMessageDialog(this, " Confirm Successful Certificate!!");
                    loadCertificateCell();
                }
            } else {
                JOptionPane.showMessageDialog(this, "not enough conditional!");
            }

        } else {
            JOptionPane.showMessageDialog(this, "Please Select Student do you want Confirm!");
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void txtOldPassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtOldPassActionPerformed
        // TODO add your handling code here:
        btnChange1ActionPerformed(evt);

    }//GEN-LAST:event_txtOldPassActionPerformed

    private void txtNewPassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNewPassActionPerformed
        // TODO add your handling code here:
        btnChange1ActionPerformed(evt);
    }//GEN-LAST:event_txtNewPassActionPerformed

    private void txtRePassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtRePassActionPerformed
        // TODO add your handling code here:
        btnChange1ActionPerformed(evt);
    }//GEN-LAST:event_txtRePassActionPerformed
    /**
     * @param args the command line arguments
     */
    public boolean validateInformation() {
        oldPassword = txtOldPass.getText();
        if (oldPassword.equals("")) {
            JOptionPane.showMessageDialog(this, "you must input your old password!");
            txtOldPass.requestFocus();
            return false;
        }
        newPassword = txtNewPass.getText();
        if (newPassword.equals("")) {
            JOptionPane.showMessageDialog(this, "you must input your new password!");
            txtNewPass.requestFocus();
            return false;
        }
        if (newPassword.length() < 6) {
            JOptionPane.showMessageDialog(this, "Password >6 character!");
            txtNewPass.requestFocus();
            return false;
        }
        reNewPassword = txtRePass.getText();
        if (reNewPassword.equals("")) {
            JOptionPane.showMessageDialog(this, "you must input your confirm new passWord!");
            txtRePass.requestFocus();
            return false;
        }
        if (!newPassword.equals(reNewPassword)) {
            JOptionPane.showMessageDialog(this, "Your password do not match ");
            txtRePass.setText("");
            txtRePass.requestFocus();
            return false;
        }
        return true;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToggleButton btnChange1;
    private javax.swing.JButton btnClose1;
    private javax.swing.JButton btnClose2;
    private javax.swing.JToggleButton btnDetail;
    private javax.swing.JButton btnSearch;
    private creator.components.CheckBoxList cblCourseSearch;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JLabel lbUserName;
    private javax.swing.JLabel lbUserName1;
    private javax.swing.JTable tbInfo;
    private javax.swing.JPasswordField txtNewPass;
    private javax.swing.JPasswordField txtOldPass;
    private javax.swing.JPasswordField txtRePass;
    private javax.swing.JTextField txtStuNameSearch;
    // End of variables declaration//GEN-END:variables
}
